//
//  CommentCell.m
//  DialectShare
//
//  Created by timmy zhong on 4/1/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "CommentCell.h"
#import "CachedImage.h"

@interface CommentCell ()
@property (nonatomic, retain) CachedImage *avatar;
@end

@implementation CommentCell
@synthesize view = _view, avatar = _avatar;
@synthesize name = _name, content = _content, avatarContainer = _avatarContainer, date = _date;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [[NSBundle mainBundle] loadNibNamed:@"CommentCell" owner:self options:nil];
        [self addSubview:self.view];
        
        _avatar = [[CachedImage alloc] initWithFrame:self.avatarContainer.bounds];
        [self.avatarContainer addSubview:_avatar];
        
    }
    return self;
}

- (void)dealloc
{
    self.name = nil;
    self.avatarContainer = nil;
    self.date = nil;
    self.content = nil;
    self.view = nil;
    self.avatar = nil;
    
    [super dealloc];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)showComment:(Comment *)comment
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"user_icon" ofType:@"png"];
    [self.avatar showImageForUrl:comment.user.avatar defaultImage:path];
    
    self.name.text = comment.user.name;
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM/dd hh:mm"];
    NSDate *da = [NSDate dateWithTimeIntervalSince1970:comment.dateline];
    self.date.text = [formatter stringFromDate:da];
    [formatter release];

    self.content.text = comment.content;
}








@end
